/* Utility scripts for Pardus Sector Tool
 * (C) Yassen 2009
 *
 * objectinfo.js
 * Defines functions for getting object information.
 *
 * Functions:
 *
 * array   GetList(object)
 * Object  Get(object, name)
 *
 */

Utility.ObjectInfo.GetList = function(object)
{
  switch (object)
  {
    case eBuilding: return Global.BuildingInfoList;
    case ePlanet: return Global.PlanetInfoList;
    case eStarbase: return Global.StarbaseInfoList;
    case eBackground: return Global.BackgroundInfoList;
    default: throw "Unknown object type " + object;
  }
}

Utility.ObjectInfo.Get = function(object, name)
{
  if(object == eStarbase)
    return Utility.ObjectInfo.GetList(object)[name.type][(name.npc == NPC? "npc": "player")];
  
  else
    return Utility.ObjectInfo.GetList(object)[name];
}

Building.prototype.calculateUpkeep = function()
{
  var result = {};
  var info = Utility.ObjectInfo.Get(eBuilding, this.name);
  
  for(commodity in info.upkeep)
    if(info.upkeep.hasOwnProperty(commodity))
      result[commodity] = Math.round(info.upkeep[commodity] * (1 + 0.4 * (this.level - 1)));
      
  return result;
}
Building.prototype.calculateProduction = function()
{
  var result = {};
  var info = Utility.ObjectInfo.Get(eBuilding, this.name);
  
  for(commodity in info.production)
    if(info.production.hasOwnProperty(commodity))
      result[commodity] = Math.round(info.production[commodity] * (1 + 0.5 * (this.level - 1)));
      
  return result;
}
Planet.prototype.calculateUpkeep = function()
{
  var result = {};
  var info = Utility.ObjectInfo.Get(ePlanet, this.type);
  
  for(commodity in info.upkeep)
    if(info.upkeep.hasOwnProperty(commodity))
      result[commodity] = Math.round(this.population / 1000 * info.upkeep[commodity]);
      
  return result;
}
Planet.prototype.calculateProduction = function()
{
  var result = {};
  var info = Utility.ObjectInfo.Get(ePlanet, this.type);
  
  for(commodity in info.production)
    if(info.production.hasOwnProperty(commodity))
      result[commodity] = Math.round(this.population / 1000 * info.production[commodity]);
      
  return result;
}

Starbase.prototype.calculateUpkeep = function()
{
  var result = {};
  var info = Utility.ObjectInfo.Get(eStarbase, {type: this.type, npc: this.owner});
  
  for(commodity in info.upkeep)
    if(info.upkeep.hasOwnProperty(commodity))
      result[commodity] = Math.round(this.population / 1000 * info.upkeep[commodity]);
      
  return result;
}
Starbase.prototype.calculateProduction = function()
{
  var result = {};
  var info = Utility.ObjectInfo.Get(eStarbase, {type: this.type, npc: this.owner});
  
  for(commodity in info.production)
    if(info.production.hasOwnProperty(commodity))
      result[commodity] = Math.round(this.population / 1000 * info.production[commodity]);
      
  return result;
}